package DynamicProgramming;

public class _213_HouseRobberII {
    int[] nums;
    public int rob(int[] nums) {
        if (nums == null && nums.length == 0) {
            return 0;
        } else if (nums.length == 1) {
            return nums[0];
        }
        this.nums = nums;
        return Math.max(robber(0, nums.length - 2), robber(1, nums.length - 1));

    }

    public int robber(int start, int  end) {
        int cur = 0, prev = 0, preprev = 0;
        while (start <= end) {
            cur = Math.max(preprev + nums[start], prev);
            preprev = prev;
            prev = cur;
            start++;
        }
        return cur;
    }

}
